package com.wei.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wei.health.model.entity.TBodyInfo;
import com.wei.health.model.entity.TUser;
import com.wei.health.model.vo.UserInfoVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TUserMapper extends BaseMapper<TUser> {

    @Select("SELECT * FROM t_user WHERE user_name = #{userName}")
    TUser selectByUserName(@Param("userName") String userName);

    @Select("SELECT * FROM t_user WHERE id = #{userId}")
    TUser selectById(@Param("userId") int id);

    @Insert("INSERT INTO t_user (creator, create_time, updater, update_time, nick_name, user_name, password) "
            + "VALUE (0, NOW(), 0, NOW(), #{userName}, #{userName}, #{password})")
    int insertByOne(TUser tUser);

    @Update("UPDATE t_user SET updater = #{id}, update_time = NOW(), password = #{password} WHERE id = #{id}")
    int updateByOne(TUser tUser);

    @Update("UPDATE t_user SET updater = #{id}, update_time = NOW(), nick_name = #{nickName}, email = #{email}, head_url = #{headUrl} WHERE id = #{id}")
    int updateByUserInfoOne(TUser tUser);

    @Select("SELECT * FROM t_user")
    List<UserInfoVo> userList();

    @Delete("DELETE FROM t_user WHERE id = #{id}")
    int deleteByOne(@Param("id") int id);

    @Select("SELECT * FROM t_user WHERE id = #{id}")
    TUser selectByUserOne(@Param("id") int id);

}